use warnings;
use Scalar::Util qw(looks_like_number);
require '../perl/FilterData.pl';

open(FOO,"../perl/GENE_HD.txt");
open(OUT, '> GENE_HD_R.txt');
open(COLS, "../perl/GENE_Cols.txt");

#Reading column names from GENE_Cols.txt
my @aGene;
my $count = 0;
while(<COLS>)
{
    chomp;
    $t = $_;
    $aGene[$count++] = $t;
}

print OUT "y\tcensor\t";
for(my $i = 0; $i < $#aGene + 1; $i++)
{
    print OUT "$aGene[$i]\t";
}
print OUT "\n";

while(<FOO>)
{
    chomp;
    my @arr = split " ";
    my @t  = split ":",$arr[0];
    print OUT "$t[0]\t$t[1]\t";
    my $count = 1;
    my $i = 1;
    while($i < $#arr + 1)
    {
	@t  = split ":",$arr[$i++];
	my $t0 = sprintf("%.3f",trimIfEmpty($t[0]));
	while($t0 > $count)
	{
	    print OUT "0.000\t";
	    $count++;
	}
	print OUT "$t[1]\t";
	$count++;
    }
    while($count <= $#aGene + 1)
    {
	print OUT "0.000\t";
	$count++;
    }
    print OUT "\n";
}

close(OUT);
close(FOO);
close(COLS);